﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace EXAM
{
    public partial class News : System.Web.UI.Page
    {
        string sErr = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                long idnews = LoadDataList();
                //SetDataToPage(idnews);
            }
        }

        private void SetDataToPage(long idnews)
        {

        }

        private long LoadDataList()
        {
            long idNews = 0;
            BUS.NewsControl ctr = new BUS.NewsControl();
            DataTable dt = ctr.GetByStatus(1,ref sErr);
            if (Request["newsID"] != null)
            {
                idNews = Convert.ToInt64(Request["newsID"]);
                DTO.NewsInfo inf = ctr.Get(idNews, ref sErr);
                lbContent.Text = inf.LongDecribes;
            }
            else
            {
                DTO.NewsInfo inf = ctr.GetDefault(ref sErr);
                lbContent.Text = inf.LongDecribes;
                idNews = inf.ID;
            }
            DataRow[] arrrow = dt.Select("ID=" + idNews);
            if (arrrow.Length == 1)
            {
                dt.Rows.Remove(arrrow[0]);
            }
            dgvNews.DataSource = dt;
            dgvNews.DataBind();
            return idNews;
        }
    }
}
